package orgs.example.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import orgs.example.pojo.User;

@Mapper
public interface UserMapper {
    @Select("select * from user where user_account=#{useAccount}")
    User findByUserAccount(String userAccount);

    @Insert("INSERT INTO user (user_account, user_password, user_name, user_role, user_status, user_company, user_telephone) " +
            "VALUES (#{userAccount}, #{userPassword}, #{userName}, #{userRole}, #{userStatus}, #{userCompany}, #{userTelephone})")
    void register(User user);

    @Select("select * from user where user_id=#{id}")
    User findByUserId(Integer id);


    @Update("<script>" +
            "UPDATE user " +
            "<set>" +
            "<if test='userAccount != null'> user_account = #{userAccount}, </if>" +
            "<if test='userPassword != null'> user_password = #{userPassword}, </if>" +
            "<if test='userName != null'> user_name = #{userName}, </if>" +
            "<if test='userRole != null'> user_role = #{userRole}, </if>" +
            "<if test='userStatus != null'> user_status = #{userStatus}, </if>" +
            "<if test='userCompany != null'> user_company = #{userCompany}, </if>" +
            "<if test='userTelephone != null'> user_telephone = #{userTelephone} </if>" +
            "</set>" +
            "WHERE user_id = #{userId}" +
            "</script>")
    void edituserInfo(User user);


}
